#pragma once
#include "AMQPClient.h"
#include "boost/asio.hpp"
#include <functional>
#include <thread>
typedef std::function <bool(const amqp::EnvelopePtr &)> MQ_MSG_FUNC;
typedef std::vector<std::string> Strings;

class RabbitMQ {
  public:
    RabbitMQ();
    ~RabbitMQ();

  public:
    void init(const std::string& uri, const std::string& exchange,
              const std::string& queue, const Strings& routers, MQ_MSG_FUNC call_func);
    void ack(const amqp::EnvelopePtr& msg);

    void quit();

  private:
    void start(const boost::system::error_code& e);

  private:
    amqp::ChannelPtr    m_channel;

    std::string         m_queue_name = "que_HelloApp";
    std::string         m_exchange_name = "exg_HelloApp";
    std::string         m_mq_uri = "amqp://user:pwd@192.168.1.21:5683/";

    MQ_MSG_FUNC         m_func;
    Strings             m_routers;

  private:
    bool                m_quit;
    std::shared_ptr<std::thread>    m_thread_ptr;
    boost::asio::io_service         m_io_ctx;
    boost::asio::io_service::work   m_io_work;
    boost::asio::deadline_timer     m_timer;
};